$(document).ready(function(){
    //监听回车事件
    document.onkeydown = function (event) {
        var e = event || window.event;
        if (e && e.keyCode == 13) { //回车键的键值为13
            $("#loginsubmit").click(); //调用登录按钮的登录事件
        }
    };
    // 图形验证码
    $('.login-captcha').bind("click", function() {
        this.src = this.src + '?t=' + (new Date).getTime();
    })
    // 登录
    $("#loginsubmit").bind("click", function () {
        $.ajax({
            type: "POST",
            url:"/doLogin",
            data:$('#loginfm').serialize(),
            error: function(request) {
                myAlert('系统提示',"Connection error");
            },
            success: function(data) {
                if(data.status==1){
                    localStorage.setItem("userSession", JSON.stringify(data.data));
                    myAlert('系统提示',data.message,function() {
                        window.location.reload();
                    });
                }else{
                    myAlert('系统提示',data.message);
                }
            }
        });
    })
    //注册
    $("#registersubmit").bind("click", function () {
        $.ajax({
            type: "POST",
            url:"/doRegister",
            data:$('#registerfm').serialize(),
            error: function(request) {
                myAlert('系统提示',"Connection error");
            },
            success: function(data) {
                if(data.status==1){
                    myAlert('系统提示',data.message,function() {
                        window.location.reload();
                    });
                }else{
                    myAlert('系统提示',data.message);
                }
            }
        });
    })
    //重置密码
    $("#resetpasswordsubmit").bind("click", function() {
        alert("该功能还在开发，尽情期待！");
    })
})
